package cn.laixueit.controller;

import cn.laixueit.pojo.Category;
import cn.laixueit.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

@Controller
@RequestMapping("/category")
public class CategoryController {

    @Autowired
    private CategoryService categoryService;

    @GetMapping("/list")
    public ResponseEntity<List<Category>> list(@RequestParam("pid")Long pid){
        List<Category> categoryList =  categoryService.listByPid(pid);
        return ResponseEntity.ok(categoryList);
    }

    @GetMapping("/getById/{id}")
    public ResponseEntity<Category> getById(@PathVariable("id")Long id){
        Category category = categoryService.getById(id);
        return ResponseEntity.ok(category);
    }

    @GetMapping("/findCnameByList")
    public ResponseEntity<List<Category>> findCnameByList(@RequestParam List<Long> cids){
        List<Category> list = categoryService.findCnameByList(cids);
        return ResponseEntity.ok(list);
    }
}
